package cn.micro.keep.accounts.service.impl;

import cn.micro.keep.accounts.common.utils.SecurityUtil;
import cn.micro.keep.accounts.entity.AccountDimUser;
import cn.micro.keep.accounts.entity.dto.EditPasswordDTO;
import cn.micro.keep.accounts.entity.dto.UserDTO;
import cn.micro.keep.accounts.entity.vo.UserCommonStatVO;
import cn.micro.keep.accounts.entity.vo.UserDetailVO;
import cn.micro.keep.accounts.mapper.AccountDimUserMapper;
import cn.micro.keep.accounts.mapstruct.AccountDimUserMapstruct;
import cn.micro.keep.accounts.service.AccountDimUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author 柘阳科技
 * @since 2023-11-08
 */
@Service
public class AccountDimUserServiceImpl extends ServiceImpl<AccountDimUserMapper, AccountDimUser> implements AccountDimUserService {

    @Override
    public boolean editPassword(EditPasswordDTO dto) {
        return false;
    }

    @Override
    public boolean editUserInfo(UserDTO dto) {
        AccountDimUser user = new AccountDimUser();
        AccountDimUserMapstruct.INSTANCE.dtoToEntity(dto,user);
        user.setId(SecurityUtil.getUserId());
        return this.updateById(user);
    }

    @Override
    public AccountDimUser getByUsernameOrPhoneOrOpenId(String value) {
        return this.baseMapper.queryByUsernameOrPhoneOrOpenId(value);
    }

    @Override
    public UserDetailVO getDetail(Long userId) {
        return this.baseMapper.queryById(userId);
    }

    @Override
    public UserCommonStatVO commonStat() {
        Long userId = SecurityUtil.getUserId();
        return this.baseMapper.queryCommonStat(userId);
    }
}
